/*
 * @Author: hcluo
 * @Date: 2020-07-20 20:26:21
 * @LastEditors: hcluo
 * @LastEditTime: 2020-07-20 23:04:26
 */

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpack = require('webpack');

module.exports = {
	mode: 'development',
	optimization: {
		minimize: false,
	},
	entry: './main.js',
	output: {
		filename: 'main.js',
		path: path.resolve(__dirname, 'dist'),
	},
	module: {
		rules: [
			{
				test: /\.js$/,
				use: {
					loader: 'babel-loader',
					options: {
						presets: ['@babel/preset-env'],
						plugins: [
							[
								'@babel/plugin-transform-react-jsx',
								{ pragma: 'ToyReact.createElement' },
							],
						],
					},
				},
			},
		],
	},
	plugins: [
		new CleanWebpackPlugin(),
		new HtmlWebpackPlugin({
			template: path.resolve('./main.html'),
		}),
		new webpack.NamedModulesPlugin(), // 用于启动 HMR 时可以显示模块的相对路径
		new webpack.HotModuleReplacementPlugin(), // Hot Module Replacement 的插件
	],
	optimization: {
		minimize: false,
	},
	devtool: 'source-map',
	devServer: {
		open: 'Chrome',
		hot: true,
	},
};
